package com.dingding.nettyserver.modular.speicial.push.impl;

import java.math.BigDecimal;

import org.springframework.stereotype.Component;
import com.aliyun.openservices.ons.api.Action;
import com.dingding.common.core.push.pushbean.specialdriver.AppointSpecialOrderPushBean;
import com.dingding.common.core.push.pushmsg.TcpPushPack;
import com.dingding.common.core.util.JSONUtil;
import com.dingding.common.core.util.paravalidate.ValiResult;
import com.dingding.common.core.util.paravalidate.ValidateUtil;
import com.dingding.nettyserver.common.handler.AbstractPushHandler;
import com.dingding.nettyserver.common.protocolbuf.PushProtobuf.SecialOrderAppoint;
import com.dingding.nettyserver.core.util.DateKit;
import com.dingding.nettyserver.core.util.NumUtil;
import com.dingding.nettyserver.modular.speicial.push.ISpecialPushHandler;

/**
 * @Description 专车业务，推送模块
 * @author fengshuonan
 * @date 2016年11月30日 下午5:12:17
 */
@Component
public class SpecialPushHandlerImpl extends AbstractPushHandler implements ISpecialPushHandler {

	/**
	 * @Description 指派订单推送
	 * @author fengshuonan
	 */
	@Override
	public Action appointOrder(TcpPushPack tcpPushPack) {
		AppointSpecialOrderPushBean o = JSONUtil.parseObject(tcpPushPack.getContent(),
				AppointSpecialOrderPushBean.class);

		ValiResult validateBean = ValidateUtil.validateBeanIsAvaliable(o, AppointSpecialOrderPushBean.class);
		System.out.println(validateBean.getNullFieldName());
		o.setDistance(new BigDecimal(0));
		o.setTotalMoney(new BigDecimal(0));

		SecialOrderAppoint secialOrderAppoint = SecialOrderAppoint.newBuilder().setNickName(o.getNickName())
				.setSex(o.getSex()).setTelePhone(o.getTelePhone()).setUserAvatar(o.getUserAvatar())
				.setUserTabloidAvatar(o.getUserTabloidAvatar()).setOid(o.getOid())
				.setDistance(NumUtil.keep2Point(o.getDistance().doubleValue())).setEndAddress(o.getEndAddress())
				.setEndLatitude(NumUtil.latLngPoint(o.getEndLatitude()))
				.setEndLongitude(NumUtil.latLngPoint(o.getEndLongitude())).setOrderStatus(o.getOrderStatus())
				.setSetOutTime(DateKit.getTime(o.getSetOutTime())).setSetOutType(o.getSetOutType())
				.setStartAddress(o.getStartAddress()).setStartLatitude(NumUtil.latLngPoint(o.getStartLatitude()))
				.setStartLongitude(NumUtil.latLngPoint(o.getStartLongitude())).setOutTime(o.getOutTime())
				.setEstimateDuration(o.getEstimateDuration().intValue()).setStartDistance(NumUtil.keep2Point(o.getStartDistance().doubleValue()))
				.setOtherUserId(o.getOtherUserId()).setEstimateDistance(NumUtil.keep2Point(o.getEstimateDistance().doubleValue()))
				.setEstimateMoney(NumUtil.keep1Point(o.getEstimateMoney().doubleValue()))
				.setTotalMoney(NumUtil.keep1Point(o.getTotalMoney().doubleValue())).setPublishType(o.getPublishType()).build();
		
		return super.pushToClient(tcpPushPack, secialOrderAppoint);
	}

}
